package com.ueboot.weishop.admin.batch.tasklet;

import com.ueboot.weishop.entity.activity.CrowResultEntity;
import com.ueboot.weishop.entity.order.OrderEnum;
import com.ueboot.weishop.service.activity.CrowResultService;
import com.ueboot.weishop.service.lottery.LotteryRecordService;
import com.ueboot.weishop.service.order.OrderService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class SendDmsStepFirstTasklet implements Tasklet {
	private Logger logger = LoggerFactory.getLogger(this.getClass());

	@Autowired
	private OrderService orderService;
	@Autowired
	private LotteryRecordService lotteryRecordService;
	@Autowired
	private CrowResultService crowResultService;

	public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) {
		String category1 = "101";//福宝零件套餐
		String category5 = "105";//折扣购
		Integer countOrder15 = orderService.updateExtStatusByExtStatusAndOrderStatusAndCategory(OrderEnum.EXT_STATUS_1, OrderEnum.EXT_STATUS_0, OrderEnum.ORDER_STATUS_2, category1, category5);
		logger.info("下发DMS优惠券跑批任务 step one 修改订单已支付的extStatus......本次修改订单extStatus数据条数:countOrder15{}", countOrder15);
		Integer countLottery = lotteryRecordService.updateExtStatusByExtStatus(OrderEnum.EXT_STATUS_1, OrderEnum.EXT_STATUS_0);
		logger.info("下发DMS优惠券跑批任务 step one 修改抽奖的extStatus......本次修改抽奖extStatus数据条数: {}", countLottery);
		Integer crowResult = crowResultService.updateIssueDmsByIssueDms(CrowResultEntity.ISSUE_DMS_2, CrowResultEntity.ISSUE_DMS_1);
		logger.info("下发DMS众筹中奖跑批任务 step one 修改众筹下发字段的issueDms......本次修改众筹issueDms数据条数: {}", crowResult);
		return RepeatStatus.FINISHED;
	}
}